package com.crawler.parser;

import java.util.Map;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

import com.google.common.collect.Maps;

public class LoginPageParser extends ParserAdapter {

	/**
	 * 解析验证码
	 */
	@Override
	public String parseText(String html) {
		Document doc = Jsoup.parse(html);
		String src = doc.getElementById("JD_Verification1").attr("src2");
		return src;
	}

	/**
	 * 解析Token
	 */
	@Override
	public Map<String, Object> parseMap(String html) {
		Map<String, Object> map = Maps.newHashMap();
		Document doc = Jsoup.parse(html);
		Elements inputs = doc.getElementsByAttributeValue("type", "hidden");
		String uuid = inputs.get(0).attr("value");
		String iname = inputs.get(5).attr("name");
		String ivalue = inputs.get(5).attr("value");
		map.put("uuid", uuid);
		map.put("iname", iname);
		map.put("ivalue", ivalue);
		return map;
	}
	
}
